package com.baikeyang.app.aspect;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;

/**
 * AOP 日志
 * Created by lenovo on 2018/7/12.
 */
@Aspect
@Order
public class SysLogAspect {

    private final static Logger log = LogManager.getLogger(MyAspect.class);

    @Pointcut("execution (* com.baikeyang.service..impl.*Impl.*(..))")
    public void anyMethod() {
        System.out.println("声明一个切入点");
    }// 声明一个切入点

    @Before("anyMethod() && args(name)")
    public void doAccessCheck(String name) {
        log.info("前置通知:" + name);
    }

    @AfterReturning(pointcut = "anyMethod()", returning = "result")
    public void doAfterReturning(String result) {
        log.info("后置通知:" + result);
    }

    @After("anyMethod()")
    public void doAfter() {
        log.info("最终通知");
    }

    @AfterThrowing(pointcut = "anyMethod()", throwing = "e")
    public void doAfterThrowing(Exception e) {
        log.info("例外通知:" + e);
    }

    @Around("anyMethod()")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
        // if(){//判断用户是否在权限
        log.info("进入方法");
        Object result = pjp.proceed();
        log.info("退出方法");
        // }
        return result;
    }

}
